package com.example.automanagement.controller;

import com.example.automanagement.dto.OrderDto;
import com.example.automanagement.entity.AutoOrder;
import com.example.automanagement.entity.RepairOrder;
import com.example.automanagement.service.OrderService;
import com.example.automanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping(value = "/getAutoOrder")
    public Result getAutoOrder(@RequestParam("userId") String userId,@RequestParam("role") String userRole){
        try {
            List<AutoOrder> autoOrder =orderService.getAutoOrder(userId,userRole);
            return Result.success(autoOrder,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }

    //获取用车工单详情
    @GetMapping(value = "/getAutoOrderDetail")
    public Result getAutoOrderDetail(@RequestParam("autoOrderId") String autoOrderId){
        AutoOrder autoOrder =  orderService.getAutoOrderDetail(autoOrderId);
        if(autoOrder==null)
            return Result.error("500","查询失败");
        return Result.success(autoOrder,"查询成功");
    }

    //获取维修工单详情
    @GetMapping(value = "/getRepairOrderDetail")
    public Result getRepairOrderDetail(@RequestParam("repairOrderId") String repairOrderId){
        RepairOrder repairOrder =  orderService.getRepairOrderDetail(repairOrderId);
        if(repairOrder==null)
            return Result.error("500","查询失败");
        return Result.success(repairOrder,"查询成功");
    }

    @GetMapping(value = "/getFixOrder")
    public Result getFixOrder(@RequestParam("userId") String userId,@RequestParam("role") String userRole){
        try {
            List<RepairOrder> fixOrder =orderService.getFixOrder(userId,userRole);
            return Result.success(fixOrder,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }

    // 获取维修和用车工单
    @GetMapping(value = "/getOrder")
    public Result getOrder(@RequestParam("userId") String userId,@RequestParam("role") String userRole){
        try {
            List<OrderDto> order =orderService.getOrder(userId,userRole);
            return Result.success(order,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
}
